package com.car.dao.impl;

import com.car.dao.EmployeeDao;
import com.car.domain.Employee;
import com.car.utils.JDBCUtils;

import java.util.List;

public class EmployeeDaoImpl implements EmployeeDao {
    @Override
    public int add(Employee emp) throws Exception {
        String sql="insert into t_employee(name,age,gender,work_Id,salary)"+
                " values(?,?,?,?,?)";
        return JDBCUtils.update(sql,emp.getName(),emp.getAge(),emp.getGender(),emp.getWorkId(),emp.getSalary());
    }

    @Override
    public int delete(int id) throws Exception {
        String sql="delete from t_employee where id=?";
        return JDBCUtils.update(sql,id);

    }

    @Override
    public int update(Employee emp) throws Exception {
        String sql="update t_employee set name=?,age=?,gender=?,work_Id=?,salary=?" +
                "where id=?";

        return JDBCUtils.update(sql,emp.getName(),emp.getAge(),emp.getGender(),emp.getWorkId(),emp.getSalary(),emp.getId());

    }

    @Override
    public Employee queryById(int id) throws Exception {
        String sql="select * from t_employee where id=?";
        return JDBCUtils.query(sql,Employee.class,id);
    }

    @Override
    public List<Employee> queryAll() throws Exception {
    String sql="select * from t_employee";
    return JDBCUtils.querylist(sql,Employee.class);
    }
}
